package com.xhsj.user.hr.userInfo.service;

import com.xhsj.user.hr.userInfo.entity.TbGlobalUserContractType;
import com.xhsj.user.hr.userInfo.mapper.TbGlobalUserContractTypeMapper;
import com.xhsj.user.hr.userInfo.service.TbGlobalUserContractTypeService;
import com.xhsj.user.hr.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.*;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 用户_合同类型 服务实现类
 * </p>
 *
 * @author liuqinghua
 * @since May 31, 2021 8:09:34 AM
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class TbGlobalUserContractTypeService extends BaseService<TbGlobalUserContractTypeMapper, TbGlobalUserContractType>{
    @Autowired
    private TbGlobalUserContractTypeMapper dao;

	/**
	 * 保存
	 * @author liuqinghua
	 * @date May 31, 2021 8:09:34 AM
	 */
    @Override
    public boolean save(TbGlobalUserContractType entity) {
        return super.save(entity);
    }

	/**
	 * 通过id获取数据
	 * @author liuqinghua
	 * @date May 31, 2021 8:09:34 AM
	 */
    @Override
    public TbGlobalUserContractType getById(Serializable id) {
        return super.getById(id);
    }

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date May 31, 2021 8:09:34 AM
	 */
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

	/**
	 * 分页查询数据
	 * @author liuqinghua
	 * @date May 31, 2021 8:09:34 AM
	 */
    public IPage<TbGlobalUserContractType> selectPage(Map<String,Object> data) {
        int currentPage=1;
        if (!Objects.isNull(data.get("page"))) {
            currentPage=(Integer) data.get("page");
        }
        int pageSize=20;
        if (!Objects.isNull(data.get("size"))) {
            pageSize=(Integer) data.get("size");
        }

        TbGlobalUserContractType entity = JSON.parseObject(JSON.toJSONString(data), TbGlobalUserContractType.class);
        Page<TbGlobalUserContractType> page = new Page(currentPage,pageSize);
        QueryWrapper<TbGlobalUserContractType> wrapper = new QueryWrapper(entity);
        return super.selectPage(page, wrapper);
    }

	/**
	 * 查询所有数据
	 * @author liuqinghua
	 * @date May 31, 2021 8:09:34 AM
	 */
    @Override
    public List<TbGlobalUserContractType> selectAll() {
        return super.selectAll();
    }


    /**
     * 合同类型
     * @author liuqinghua
     * @date May 31, 2021 8:09:34 AM
     */
    public List<Map<String,String>> findContractType() {
        List<Map<String, String>> contractType = dao.findContractType();
        List<Map<String, String>> collect = contractType.stream().map(this::toMap)
                .collect(Collectors.toList());
        return collect;
    }

    private Map<String, String> toMap(Map<String,String> user) {
         Map<String, String> map = new HashMap<>();
         map.put("label", String.valueOf(user.get("label")));
         map.put("value", String.valueOf(user.get("value")));
         return map;
    }
}
